﻿using Business;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BookManageSys.User
{
    public partial class UserOrderdetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            UsersEntity ue = new UsersEntity();
            ue.Username = Session["UserName"].ToString();

            OrderdetailsBusiness odb = new OrderdetailsBusiness();
            DataTable dt = odb.GetUserAllData(ue);

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            OrderdetailsEntity ode = new OrderdetailsEntity();
            ode.Productname = TxtSearch.Text;

            OrderdetailsBusiness odb = new OrderdetailsBusiness();
            DataTable dt = odb.SearchAllData(ode);

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        protected void ChkAll_CheckedChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox chkSelect = (CheckBox)row.FindControl("ChkSelect");
                if (ChkAll.Checked)
                {
                    chkSelect.Checked = true;
                }
                else
                {
                    chkSelect.Checked = false;
                }
            }
        }

        protected void BtnDelete_Click(object sender, EventArgs e)
        {
            string sql = "";
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox chkSelect = (CheckBox)row.FindControl("ChkSelect");

                if (chkSelect.Checked)
                {
                    string data = row.Cells[1].Text;
                    sql += " or orderdetailid = " + data;
                }
            }

            OrderdetailsBusiness odb = new OrderdetailsBusiness();
            int res = odb.DeleteMoreOrderdetail(sql);

            if (res > 0)
            {
                Response.Write("<script>alert('删除成功！')</script>");
                BindData();
            }
            else
            {
                Response.Write("<script>alert('删除失败！')</script>");
            }
        }
    }
}